<?php namespace Home\Controller; 


//测试控制器
class ContentController extends CommonController{

	public function index(){
		$gid = Q("get.g_id",0,"intval");
		$goodData = Db::table("360mall_goods")->where("g_id",$gid)->first();
		$goodData['img'] = Db::table("360mall_gdetail")->where("gd_gid",$gid)->get();
		foreach ($goodData['img'] as $k => $v) {
			$goodData['img'][$k]['gd_small'] = explode(",", $v['gd_small']);
			$goodData['img'][$k]['gd_medium'] = explode(",", $v['gd_medium']);
			$goodData['img'][$k]['gd_big'] = explode(",", $v['gd_big']);
		}
		$tid = Db::table("360mall_goods")->where("g_id",$gid)->pluck("g_tid");
$goodData['spec'] = Db::table("360mall_type_attr")->where("ta_type_id",$tid)->where("class",1)->get();
$tids = Db::table("360mall_goods")->where("g_id",$gid)->pluck("g_tid");
$goodData['attr'] = Db::table("360mall_type_attr")->where("ta_type_id",$tids)->where("class",0)->field("ta_name","ta_id")->get();
	foreach ($goodData['spec'] as $k => $v) {
		$goodData['spec'][$k]["select"] = Db::table("360mall_goods_attr")->where("ga_taid",$v['ta_id'])->where("ga_gid",$gid)->where('ga_value','!=',0)->get();
	}

	foreach ($goodData['attr'] as $k => $v) {
		$goodData['attr'][$k]["select"] = Db::table("360mall_goods_attr")->where("ga_taid",$v['ta_id'])->where("ga_gid",$gid)->where('ga_value','!=',0)->get();
	}
//	p($goodData);

		View::with("goodData",$goodData);
		View::make();
	}
////获得购物车数据
public function getdata(){
//	
//	$data = [ 
//  'id'        => 1, // 商品 ID 
//  'name'      =>' 后盾网 PHP 视频教程光盘 ',// 商品名称 
//  'num'       => 2, // 商品数量 
//  'price'     => 988, // 商品价格 
//  'options' => array(// 其他参数如价格、颜色、可以为数组或字符串 
//  'color'     => 'red', 
//  'size'  => 'L' ,
//]; 
//cart::add($data); // 添加到购物车 
//p($_SESSION); 


  	if(IS_AJAX){
  	    $gid = $_POST['gid'];
		$num =  $_POST['num'];
		$name = $_POST['name'];
		$price = $_POST['price'];
		$spec = $_POST['spec'];

		$data = array(
		   'id'=>$gid,
		   'name'=>$name,
		   'price'=>$price,
		   'options' =>$spec,
		   'num'=>$num,
		);	
	Cart::add($data); // 添加到购物车 

echo json_encode($_SESSION);
  	}
  }

}